﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Arraylists
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList bookName = new ArrayList();
            bookName.Add("《三体》");
            bookName.Add("《从你的全世界路过》");
            bookName.Add("《权力的游戏》");
            Console.WriteLine("\n数组列表容量为：{0}，元素有：{1}", bookName.Capacity,bookName.Count);
            Console.WriteLine("\n请输入想添加的图书名：");
            string flag = null;
            while (true)
            {
                string newName = Console.ReadLine();
                bookName.Add(newName);
                Console.WriteLine("还需要添加吗？（Yes/No）");
                flag = Console.ReadLine();
                if (flag.Equals("No"))
                {
                    break;
                }
            }
            Console.WriteLine("\n请输入你要查找的书名");
            while (true)
            {
                string findName = Console.ReadLine();
                if (bookName.Contains(findName))
                {
                    Console.WriteLine("书籍总共有{0}",findName);
                }
                else
                {
                    Console.WriteLine("找不到此书");
                }
                Console.WriteLine("还需要添加吗？（Yes/No）");
                flag = Console.ReadLine();
                if (flag.Equals("No"))
                {
                    break;
                }
            }
            Console.WriteLine("\n书籍总共有:");
            foreach (string name in bookName)
            {
                Console.WriteLine(name);
            }
            Console.ReadKey();
        }
    }
}
